package com.utils;


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

/***
 * adb 工具 读数据线程
 * @Author maochuang.li
 *
 * @Email maochuang.li@fuyinhy.com
 *
 * @Date Create in 16:27 2018/1/4 0004
 */
public class AdbCmdUtils {


    /**
     * adb 文件路径
     */
    private String adbFilePath;


    public AdbCmdUtils(String adbFilePath) {
        this.adbFilePath = adbFilePath;
    }

    public String runExe(String cmd) {
        Runtime rt = Runtime.getRuntime();
        Process dir = null;
        try {
            dir = rt.exec(adbFilePath + " " + cmd);
            InputStream inputStream = dir.getInputStream();
            StringBuffer stringBuffer = new StringBuffer();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
            while (true) {
                String readLine = bufferedReader.readLine();
                sysOut(readLine);
                stringBuffer.append(readLine);
                if (readLine == null || "".equals(readLine))
                    break;
            }
            return stringBuffer.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 输出系统返回数据
     *
     * @param str
     */
    private void sysOut(String str) {
        System.out.println(OtherUtils.getNowDate() + " System Return Data : " + str);
    }


}
